package com.heima.news.controller;


import com.heima.news.domain.NewsType;
import com.heima.news.service.INewsTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻类型Controller
 * 
 * @author xiecong
 * @date 2025-06-21
 */
@RestController
@RequestMapping("/newsType")
public class NewsTypeController extends BaseController
{
    @Autowired
    private INewsTypeService newsTypeService;


    /**
     * 分页查询新闻类型列表
     * @param newsType
     * @return
     */
    @RequiresPermissions("news:newsType:list")
    @GetMapping("/list")
    public TableDataInfo list(NewsType newsType)
    {
        startPage();
        List<NewsType> list = newsTypeService.selectNewsTypeTableList(newsType);
        return getDataTable(list);
    }

    @RequiresPermissions("news:newsType:all")
    @GetMapping("/all")
    public List<NewsType> getAll() {
        return newsTypeService.getAll();
    }

    /**
     * 获取新闻类型详细信息
     */
    @RequiresPermissions("news:newsType:query")
    @GetMapping(value = "/{newsTypeId}")
    public AjaxResult getInfo(@PathVariable("newsTypeId") Integer newsTypeId) {
        return success(newsTypeService.selectNewsTypeByTypeId(newsTypeId));
    }

    /**
     * 新增新闻类型
     */
    @RequiresPermissions("news:newsType:add")
    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsType newsType) {
        return toAjax(newsTypeService.insertNewsType(newsType));
    }

    /**
     * 修改新闻类型
     */
    @RequiresPermissions("news:newsType:edit")
    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsType newsType) {
        return toAjax(newsTypeService.updateNewsType(newsType));
    }

    /**
     * 删除新闻类型
     */
    @RequiresPermissions("news:newsType:remove")
    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable List<Integer> typeIds) {
        return toAjax(newsTypeService.deleteNewsTypeByTypeIds(typeIds));
    }

    /*    *//**
 * 查询新闻类型列表
 *//*
    @RequiresPermissions("news:newsType:list")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value="pageNum", defaultValue = "1") Integer pageNum,
                              @RequestParam(value="pageSize", defaultValue = "10") Integer pageSize) {
        List<NewsType> list = newsTypeService.selectNewsTypeList(pageNum,pageSize);
        return getDataTable(list);
    }*/
}
